/*
 * uart.h
 *
 * Created: 2013-11-5 7:34:22
 *  Author: alivehex
 */ 


#ifndef UART_H_
#define UART_H_

#include <avr/io.h>

// enbale the debug output
#define DBG_EN	0

// enable the error output
#define ERR_EN	0

// enable the infomation output
#define INF_EN	0

#define UBRR2BDR(_UBRR) \
	(unsigned long)(F_CPU / (8 * (_UBRR + 1)))
	
#define BDR2UBRR(_BDR) \
	(F_CPU / (8 * _BDR) - 1) 

extern int uart1_open(unsigned long baudrate);
extern int uart1_close(void);
extern int uart1_putc(char c);
extern int uart1_getc(int timeout);
extern int uart1_puts(char *c);
extern void uart1_wait(void);
extern int uartRead(char *buffer, int len);
extern int kprintf(const char *str, ...);

#if (DBG_EN)
# define DBG(...)	kprintf(__VA_ARGS__); kprintf("\r\n")
#else
# define DBG(...)	while (0)
#endif

#if (ERR_EN)
# define ERR(...)	kprintf(__VA_ARGS__); kprintf("\r\n")
#else
# define ERR(...)	while (0)
#endif

#if (INF_EN)
# define INF(...)	kprintf(__VA_ARGS__); kprintf("\r\n")
#else
# define INF(...)	while (0)
#endif

#endif /* UART_H_ */